export const getDictCode=(dictCode)=>{
    if(!localStorage){
        return [];
    }

    const dataStr = localStorage.getItem("dataDict");
    if(!dataStr){
        return [];
    }

    const dictArr = JSON.parse(dataStr);

    const dictCodes = dictArr.filter((d)=>(d.dictCode === dictCode));
    return dictCodes;
        
};
export const setDictCode=(data)=>{
    const setValue = typeof data === 'string' ? [data] : data;
    localStorage.setItem('dataDict', JSON.stringify(setValue)); // auto reload
};
export const getDictCodeLabel=(dictType,value)=>{

    if(!value && value !==0){
        return null;
    }
    const dataArr = getDictCode(dictType);
    if(dataArr && dataArr.length > 0){
        const strValue = typeof value === 'string' ? value : value.toString();
        const dictCode =  dataArr.find((item)=>item.codeValue===strValue);
        if(dictCode){
            return dictCode.codeLabel;
        }else{
            return null;
        }
    }else{
        return null;
    }
};

export default getDictCodeLabel;